package com.sg.business.commons.labelprovider.work;

import com.mobnut.commons.util.file.FileUtil;
import com.mobnut.db.DBActivator;
import com.mobnut.db.model.PrimaryObject;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.sg.business.commons.labelprovider.linestyle.LineStyleHtmlLabel;
import com.sg.business.model.IModelConstants;
import com.sg.business.model.WorksPerformence;
import com.sg.business.resource.BusinessResource;

public class WorkPerformenceHtmlLabel extends LineStyleHtmlLabel {


	private DBCollection col;

	@Override
	protected String getHtmlText(PrimaryObject po) {
		if(col == null){
			col = DBActivator.getCollection(IModelConstants.DB, IModelConstants.C_WORKS_PERFORMENCE);
		}
		long cnt = col.count(new BasicDBObject().append(WorksPerformence.F_WORKID, po.get_id()));
		String selectbarUrl = cnt==0 ? null : FileUtil
				.getImageURL(BusinessResource.IMAGE_EDIT_24,
						BusinessResource.PLUGIN_ID,
						BusinessResource.IMAGE_FOLDER);

		StringBuffer sb = new StringBuffer();
		if (selectbarUrl != null) {
			String selectbar = "<img src='" //$NON-NLS-1$
					+ selectbarUrl
					+ "' style='border-style:none;position:absolute; left:0; top:4; display:block;' width='16' height='16' />"; //$NON-NLS-1$
			sb.append(selectbar);
		}

		return sb.toString();
	}
}
